<?php
class IndexAction extends BaseAction
{

    public function index()
    {
        import('@.ORG.Session');
        import('@.ORG.Cookie');
        //$cat_value = $this->_getCate();
        $Categroy = D("Categroy");

        $cat_value = $Categroy->order('fatherid asc')->select();
            
        foreach ($cat_value as $key => $value) {
            $fa[] = $value['fatherid'];
        };
        $fa = array_unique($fa);
        unset($fa[0]);
//        foreach ($fa as $key => $value) {
//            
//        }
        
         include COMMON_PATH . 'tree.php';

            $Tree = new Tree('顶级分类');
            $Categroy = D("Categroy");
            $cat_value = $Categroy->order('fatherid asc')->select();

            foreach ($cat_value AS $id => $row) {
                $Tree->setNode($row['id'], $row['fatherid'], $row['name']);
            }

        
        foreach ($fa as $key => $value) {
                    foreach ($Tree->getChilds($value) as $k => $v) {
                        $sub[$v] = $Tree->getValue($v);
                    }
                    unset($sub[0]);
            $categorys[$Tree->getValue($value)]['value'] = $sub;
            unset($sub);
        }
        $this->assign("categorys", $categorys);
//        dump($categorys);
        $this->display();
    }
    

}

?>